<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!DOCTYPE html>
  <html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件冒泡</title>
    <style>
      .fa {
        width: 400px;
        height: 400px;
        background-color: pink;
      }

      .son {
        width: 200px;
        height: 200px;
        background-color: red;
      }
    </style>
  </head>

  <body>
    <div class="fa">
      <div class="son"></div>
    </div>
    <script>
      // 事件冒泡:会依次向上调用所有父级元素的   同名事件
      // 默认开启
      const fa = document.querySelector('.fa')
      const son = document.querySelector('.son')
      document.addEventListener('click', function () {
        alert('爷爷')
      })

      // 阻止事件冒泡
      // 1.必须要有事件对象
      // 2.e.stopPropagation()
      fa.addEventListener('click', function (e) {
        alert('把把')
        e.stopPropagation()
      })

      son.addEventListener('click', function () {
        alert('儿子')
      })
    </script>
  </body>

  </html>

</body>

</html>